function [qvalue pvalue] = lincomptest(epsilon, m)
% epsilon：表示输入的二进制序列。它是一个包含一系列二进制值的数组或向量，用于进行线性复杂度检测。
% 
% m：表示每个子序列的长度。它是一个正整数，用于将输入序列划分为多个长度为m的子序列。

    n = length(epsilon);
    N = floor(length(epsilon) / m);
    epsilonList = epsilon;

    L = zeros(1, N);
    mu = (m/2) + (9 + (-1)^(m+1))/36 - (m/3 + 2/9)/(2^m);
    T = zeros(1, N);

    for i = 1:N
        L(i) = Berlekamp_Massey_algorithm(epsilonList((i-1)*m+1:i*m));
        T(i) = ((-1)^m)*(L(i) - mu) + 2/9;
    end

    V = zeros(1, 7);
    for i = 1:N
        if T(i) <= -2.5
            V(1) = V(1) + 1;
        elseif T(i) <= -1.5 && T(i) > -2.5
            V(2) = V(2) + 1;
        elseif T(i) <= -0.5 && T(i) > -1.5
            V(3) = V(3) + 1;
        elseif T(i) <= 0.5 && T(i) > -0.5
            V(4) = V(4) + 1;
        elseif T(i) <= 1.5 && T(i) > 0.5
            V(5) = V(5) + 1;
        elseif T(i) <= 2.5 && T(i) > 1.5
            V(6) = V(6) + 1;
        elseif T(i) > 2.5
            V(7) = V(7) + 1;
        end
    end

    pi = [0.010417, 0.03125, 0.125, 0.5, 0.25, 0.0625, 0.020833];
    resultV = ((V - N*pi).^2) ./ (N*pi);
    pvalue = gammaincc(3, sum(resultV)/2);
    qvalue = pvalue;
    result = struct('p', pvalue, 'q', qvalue);
end

